//
//  BIZOfficialRapidConsultDetailQuestionCell.m
//  biz
//
//  Created by zhangfuwei on 2017/7/10.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZOfficialRapidConsultDetailQuestionCell.h"
#import "BIZConsultRecordModel.h"
#import "HZPhotoGroup.h"

@interface BIZOfficialRapidConsultDetailQuestionCell ()

/** questionContent */
@property (nonatomic, strong) UILabel *questionLabel;
/** photo */
@property (nonatomic, strong) UIView *photoBgView;
/** photo */
@property (nonatomic, strong) HZPhotoGroup *photos;

/** time */
@property (nonatomic, strong) UIButton *timeButton;

@end

@implementation BIZOfficialRapidConsultDetailQuestionCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initSubViews];
        
    }
    return self;
}

- (void)initSubViews {
    
    [self.contentView addSubview:self.questionLabel];
    [self.contentView addSubview:self.photoBgView];
    [self.contentView addSubview:self.timeButton];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.questionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(10).priorityHigh();
        make.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
    }];
    
    [self.photoBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.questionLabel.mas_bottom).priorityHigh();
        make.left.right.equalTo(self.questionLabel);
        make.height.equalTo(@(0)).priorityHigh();
    }];
    
    [self.timeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.photoBgView.mas_bottom).offset(15).priorityHigh();
        make.height.equalTo(@35);
        make.left.right.bottom.equalTo(self.contentView);
    }];
    
}

#pragma mark - class method
+ (BIZOfficialRapidConsultDetailQuestionCell *)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
    BIZOfficialRapidConsultDetailQuestionCell *cell = [tableView dequeueReusableCellWithIdentifier:kOfficialConsultQuestionCellID forIndexPath:indexPath];
    
    return cell;
}

#pragma mark -- set方法
-(void)setQuestionModel:(BIZConsultRecordModel *)questionModel {
    _questionModel = questionModel;
    if (questionModel == nil) {
        return;
    }
    _questionLabel.text = questionModel.question;
    _timeButton.layer.borderColor = [UIColor zfw_ColorWithHex:0xeeedee alpha:1.0].CGColor;
    _timeButton.layer.borderWidth = 1.0f;
    [_timeButton setTitle:[NSDate stringFromTimestamp:questionModel.quDate] forState:UIControlStateNormal];
    
    NSArray *arr = [questionModel.imgs componentsSeparatedByString:@","];
    NSMutableArray *images = [NSMutableArray array];
    if (arr.count) {
        
        [arr enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {
            [images addObject:[NSString stringWithFormat:@"%@/%@/%@", kMainBaseUrl, kShowImage, obj]];
        }];
        
        self.photos.photoItemArray = images.copy;
        [self.photoBgView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.questionLabel.mas_bottom).offset(15);
            make.height.equalTo(@(self.photos.height));
        }];
    }
}

#pragma mark -- lazyload


- (UILabel *)questionLabel {
    if (!_questionLabel) {
        _questionLabel = [[UILabel alloc] init];
        _questionLabel.numberOfLines = 0;
        _questionLabel.textColor = [UIColor zfw_ColorWithHex:0x333333 alpha:1.0];
        _questionLabel.font = [UIFont fontWithName:CHINESE_BOLD_FONT_NAME size:15];
        _questionLabel.text = @"标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题";
    }
    return _questionLabel;
}

- (UIView *)photoBgView {
    if (!_photoBgView) {
        _photoBgView = [[UIView alloc] init];
        _photos = [[HZPhotoGroup alloc] init];
        [_photoBgView addSubview:_photos];
        [_photos mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(_photoBgView);
        }];
    }
    return _photoBgView;
}

- (UIButton *)timeButton {
    if (!_timeButton) {
        _timeButton = [[UIButton alloc] init];
        _timeButton.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
        _timeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        
        _timeButton.titleLabel.font = CHINESE_SYSTEM(10);
        [_timeButton setTitleColor:[UIColor zfw_ColorWithHex:0x999999 alpha:1.0] forState:UIControlStateNormal];
//        [_timeButton setTitle:@"2017-12-01 10:00:12" forState:UIControlStateNormal];
    }
    return _timeButton;
}

@end
